#include "EpollServer.hpp"
#include <memory>

static void usage(std::string process)
{
    cerr << "\nUsage: " << process << " port\n"
         << endl;
}

int myfunc(int sock)
{
    //bug
    char buffer[1024];
    ssize_t s = recv(sock, buffer, sizeof(buffer)-1, 0); //不会被阻塞
    if(s > 0)
    {
        buffer[s] = 0;
        logMessage(DEBUG, "client[%d]# %s", sock, buffer);
    }
    return s;
}

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        usage(argv[0]);
        exit(0);
    }
    unique_ptr<EpollServer> epollserver(new EpollServer(atoi(argv[1]), myfunc));
    epollserver->InitEpollServer();
    epollserver->Run();

    return 0;
}